import pathlib


def main():
    path = pathlib.Path(".")
    number = 0
    number += glob(path, "py")
    number += glob(path, "js")
    number += glob(path, "vue")
    number += glob(path, "html")
    print("\n\n" + str(path.absolute()) + "\n总代码量：" + str(number) + "行")


def glob(path: pathlib.Path, pattern):
    number = 0
    print("\n----------------------------\n代码量", "\t", pattern + "文件名")
    for i in path.rglob("*." + pattern):
        if "node_modules" in str(i):
            continue
        try:
            with open(i, "rb") as file:
                x = len(file.readlines())
                number += x
                print(x, "\t", i)
        except Exception:
            number += 0
            print("?", "\t", i, "无法访问")
    return number


if __name__ == '__main__':
    main()
